//
//  ActivityViewController.m
//  又是豆瓣
//
//  Created by dllo on 15/12/31.
//  Copyright © 2015年 dllo. All rights reserved.
//

#import "ActivityViewController.h"
#import "activityTableViewCell.h"
#import "actModel.h"
#import "UIImageView+WebCache.h"
#import "DetialViewController.h"

@interface ActivityViewController ()<UITableViewDataSource, UITableViewDelegate>

@property (nonatomic, retain) NSMutableArray *arrModel;

@end

@implementation ActivityViewController

#define WI self.view.frame.size.width
#define HE self.view.frame.size.height

- (void)dealloc {
    [super dealloc];
    
}

- (instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        
    }
    return self;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.

    self.tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, WI, HE) style:UITableViewStylePlain];
    [self.view addSubview:_tableView];
    _tableView.rowHeight = 195;
    _tableView.delegate = self;
    _tableView.dataSource = self;
    
    
    [_tableView registerClass:[activityTableViewCell class] forCellReuseIdentifier:@"cell"];
    
    [_tableView release];
    
    NSString *path = [[NSBundle mainBundle]pathForResource:@"activity" ofType:@"plist"];
    NSArray *arrData = [NSArray arrayWithContentsOfFile:path];
    
    self.arrModel = [NSMutableArray array];
    for (NSDictionary *dic in arrData) {
        actModel *model = [actModel model];
        [model setValuesForKeysWithDictionary:dic];
        [_arrModel addObject:model];
    }
    
    
self.navigationItem.title = @"活动";
//    UIView *rVC = [[UIView alloc]initWithFrame:CGRectMake(0, 0, WI, 100)];
//    rVC.backgroundColor = [UIColor yellowColor];
//    self.navigationItem.titleView = rVC;
    
    
    self.navigationController.navigationBar.barTintColor = [UIColor cyanColor];
    
    
}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return _arrModel.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    activityTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
 
    cell.imgV.image = [UIImage imageNamed:@"bg_eventlistcell@2x.png"];
    cell.imageV1.image = [UIImage imageNamed:@"icon_date@2x.png"];
    cell.imageV2.image = [UIImage imageNamed:@"icon_spot@2x.png"];
    cell.imageV3.image = [UIImage imageNamed:@"icon_catalog@2x.png"];
    actModel *mm = _arrModel[indexPath.row];
    cell.titleLabel.text = mm.title;
    NSString *str = [NSString stringWithFormat:@"%@ -- %@", [mm.begin_time substringWithRange:NSMakeRange(5, 11)], [mm.end_time substringWithRange:NSMakeRange(5, 11)]];
    cell.timeLabel.text = str;

    NSString *strIntere = [NSString stringWithFormat:@"感兴趣：%@     参加：%@", mm.wisher_count , mm.participant_count];
    
    cell.intereLabel.text = strIntere;

    cell.addressLabel.text = mm.address;
    
    cell.typeLabel.text = mm.category_name;
    
    [ cell.imageV sd_setImageWithURL:[NSURL URLWithString:mm.image]];
    
    
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    DetialViewController *dVC = [[DetialViewController alloc]init];
    [self.navigationController pushViewController:dVC animated:YES];
    dVC.model = _arrModel[indexPath.row];
    
    
}



- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
